package com.marktotop.converter;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * @Classname DateConverter
 * @Author 6b92d6
 * @Date 2021-06-23
 * @Description 日期转换
 */
@Component
public class DateConverter implements Converter<String, LocalDate> {

    /**
     * 将传入的字符转换成 yyyy-MM-dd 格式
     * @param source
     * @return
     */
    @Override
    public LocalDate convert(String source) {

        try {
            return LocalDate.parse(source, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
